﻿Public Class frmUserControls
    Dim UserIDSelected As Integer
    Private Sub btnNewUser_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNewUser.Click
        frmNewUser.btnEdit.Enabled = False
        frmNewUser.ShowDialog()
    End Sub

    Private Sub frmUserControls_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        LoadDataToLVUsers("SELECT * FROM tbl_users WHERE Status <> '1'", Me.LVUsers)
        Me.TSUser.Text = UserLogStatus

    End Sub
    Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click
        If txtFind.Text <> "" Then
            LoadDataToLVUsers("SELECT * FROM tbl_users WHERE UserID=" & Me.txtFind.Text & " AND Status <>'1'", Me.LVUsers)
            '     LoadDataToLVUsers("SELECT * FROM tbl_users WHERE  KFullName=LIKE %'" & txtFind.Text & "'% ", Me.LVUsers)
        End If
     

    End Sub

    Private Sub LVUsers_MouseDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles LVUsers.MouseDoubleClick
        Dim i As Integer
        For i = 0 To Me.LVUsers.Items.Count - 1
            If LVUsers.Items(i).Selected = True Then
                UserIDSelected = LVUsers.Items(i).Text
                Me.txtFind.Text = UserIDSelected
            End If
        Next
    End Sub
    Private Sub btnDeleteUser_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDeleteUser.Click
        If UserIDSelected = 0 Then
            MsgBox("Please double click on List View firt befor click on delete!", MsgBoxStyle.Information)
            Exit Sub
        Else
            If MsgBox("Do you want to delete this user?", MsgBoxStyle.YesNo, "Delete User") = vbYes Then
                Dim UDelete = "UPDATE tbl_users SET Status='1' WHERE UserID=" & UserIDSelected
                DeleteDataAccess(UDelete)
                UserIDSelected = 0
                LoadDataToLVUsers("SELECT * FROM tbl_users WHERE Status <> '1'", Me.LVUsers)
            Else
                MsgBox("Please click on List View befor delete!", MsgBoxStyle.Information)
            End If
        End If
        


    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            LoadDataToLVUsers("SELECT * FROM tbl_users WHERE Status <> '1'", Me.LVUsers)

    End Sub

    Private Sub btnEditUser_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEditUser.Click
        PUserID = UserIDSelected
        Edit = True
        frmNewUser.btnEdit.Enabled = True
        frmNewUser.btnSave.Enabled = False

        frmNewUser.ShowDialog()

    End Sub

    Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
        Me.Close()

    End Sub

    Private Sub LVUsers_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LVUsers.SelectedIndexChanged

    End Sub
End Class